package com.walter.auth.config.handler;

import cn.hutool.json.JSONUtil;
import com.walter.response.ResponseKit;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author wuchenxi
 * @date 2021-06-02 10:41:48
 */
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        PrintWriter writer = httpServletResponse.getWriter();
        ResponseKit<Object> success = ResponseKit.success();
        writer.write(JSONUtil.toJsonStr(success));
        writer.flush();
        writer.close();
    }
}
